package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;
import com.ruoyi.wechat.vo.DictVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "公共功能")
@RestController
@RequestMapping("/wxapi/dicData")
public class DicDataApi {

    @Autowired
    private ISysDictDataService dictDataService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Anonymous
    @ApiOperation("获取字典信息")
    @GetMapping("/getDicData")
    public AjaxResult getDicData(String dicType)
    {
        SysDictData obj = new SysDictData();
        obj.setDictType(dicType);
        List<SysDictData> list = dictDataService.selectDictDataList(obj);
        return AjaxResult.success(list);
    }
    @Anonymous
    @ApiOperation("获取字典信息")
    @GetMapping("/getAllDicData")
    public AjaxResult getAllDicData(String dicType)
    {

        SysDictData obj = new SysDictData();
        obj.setDictType("edu_plans");
        List<SysDictData> edu_plan = dictDataService.selectDictDataList(obj);
        List<DictVo> eduPlanList = edu_plan.stream().map(dictData -> {
            DictVo dictVo = new DictVo();
            dictVo.setDictLabel(dictData.getDictLabel());
            dictVo.setDictValue(dictData.getDictValue());
            dictVo.setDictType(dictData.getDictType());
            dictVo.setCssClass(dictData.getCssClass());
            dictVo.setRemark(dictData.getRemark());
            return dictVo;
        }).collect(Collectors.toList());
        obj.setDictType("degree_type");
        List<SysDictData> degree_type = dictDataService.selectDictDataList(obj);
        List<DictVo> degreeTypeList = degree_type.stream().map(dictData -> {
            DictVo dictVo = new DictVo();
            dictVo.setDictLabel(dictData.getDictLabel());
            dictVo.setDictValue(dictData.getDictValue());
            dictVo.setDictType(dictData.getDictType());
            dictVo.setCssClass(dictData.getCssClass());
            dictVo.setRemark(dictData.getRemark());
            return dictVo;
        }).collect(Collectors.toList());
        obj.setDictType("teachlanguage");
        List<SysDictData> teachlanguage = dictDataService.selectDictDataList(obj);
        List<DictVo> teachlanguageList = teachlanguage.stream().map(dictData -> {
            DictVo dictVo = new DictVo();
            dictVo.setDictLabel(dictData.getDictLabel());
            dictVo.setDictValue(dictData.getDictValue());
            dictVo.setDictType(dictData.getDictType());
            dictVo.setCssClass(dictData.getCssClass());
            dictVo.setRemark(dictData.getRemark());
            return dictVo;
        }).collect(Collectors.toList());
        obj.setDictType("opening_dates");
        List<SysDictData> openingDates = dictDataService.selectDictDataList(obj);
        List<DictVo> openingDatesList = openingDates.stream().map(dictData -> {
            DictVo dictVo = new DictVo();
            dictVo.setDictLabel(dictData.getDictLabel());
            dictVo.setDictValue(dictData.getDictValue());
            dictVo.setDictType(dictData.getDictType());
            dictVo.setCssClass(dictData.getCssClass());
            dictVo.setRemark(dictData.getRemark());
            return dictVo;
        }).collect(Collectors.toList());

        obj.setDictType("place");
        List<SysDictData> places = dictDataService.selectDictDataList(obj);
        List<DictVo> placesList = places.stream().map(dictData -> {
            DictVo dictVo = new DictVo();
            dictVo.setDictLabel(dictData.getDictLabel());
            dictVo.setDictValue(dictData.getDictValue());
            dictVo.setDictType(dictData.getDictType());
            dictVo.setCssClass(dictData.getCssClass());
            dictVo.setRemark(dictData.getRemark());
            return dictVo;
        }).collect(Collectors.toList());
        return AjaxResult.success().put("edu_plan",eduPlanList).put("degree_type",degreeTypeList).put("teachlanguage",teachlanguageList).put("openingDates",openingDatesList).put("places",placesList);
    }
}
